﻿Imports System.Data.OleDb
Imports System.Data

Partial Class AddToForum
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            If Request.Params("ID") = "" Then Response.Redirect("Forum.aspx")
            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("SingleMomMemberConnectionString").ConnectionString)
            Dim SqlString As String = "SELECT * FROM ForumComments WHERE ForumIssue_fkId=@f1"
            Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
            oleDbConn.Open()
            Dim dataReader = cmd.ExecuteReader()
            GridView2.DataSource = dataReader
            GridView2.DataBind()


        End If
    End Sub

    Protected Sub btn_AddComment_Click(sender As Object, e As EventArgs) Handles btn_AddComment.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("SingleMomMemberConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into ForumComments(Author,Contribution,ForumIssue_fkId) VALUES (@f1,@f2,@f3)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f2", tb_Contribution.Text)
        cmd.Parameters.AddWithValue("@f3", Request.Params("ID"))
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        ''''''Now, fill gridview2 with user comment and the Member Name of user
        Dim fillComments As String = "SELECT * FROM ForumComments WHERE ForumIssue_fkId=@f1"
        Dim fillCommentsCmd As OleDbCommand = New OleDbCommand(fillComments, oleDbConn)
        fillCommentsCmd.CommandType = CommandType.Text
        fillCommentsCmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
        Dim dataReader = fillCommentsCmd.ExecuteReader()
        GridView2.DataSource = dataReader
        GridView2.DataBind()

        tb_Contribution.Text = ""
        tb_Author.Text = ""
    End Sub
End Class
